package c.b.a.b.c0;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Matrix;
import android.graphics.Outline;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Region;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import c.b.a.b.c0.k;
import c.b.a.b.c0.l;
import c.b.a.b.c0.m;

public class g extends Drawable implements androidx.core.graphics.drawable.b, n {
    private static final Paint w = new Paint(1);

    /* renamed from: b  reason: collision with root package name */
    private c f1829b;
    /* access modifiers changed from: private */

    /* renamed from: c  reason: collision with root package name */
    public final m.g[] f1830c;
    /* access modifiers changed from: private */

    /* renamed from: d  reason: collision with root package name */
    public final m.g[] f1831d;
    /* access modifiers changed from: private */
    public boolean e;
    private final Matrix f;
    private final Path g;
    private final Path h;
    private final RectF i;
    private final RectF j;
    private final Region k;
    private final Region l;
    private k m;
    private final Paint n;
    private final Paint o;
    private final c.b.a.b.b0.a p;
    private final l.a q;
    private final l r;
    private PorterDuffColorFilter s;
    private PorterDuffColorFilter t;
    private Rect u;
    private final RectF v;

    class a implements l.a {
        a() {
        }

        public void a(m mVar, Matrix matrix, int i) {
            g.this.f1831d[i] = mVar.e(matrix);
        }

        public void b(m mVar, Matrix matrix, int i) {
            g.this.f1830c[i] = mVar.e(matrix);
        }
    }

    class b implements k.c {

        /* renamed from: a  reason: collision with root package name */
        final /* synthetic */ float f1833a;

        b(g gVar, float f) {
            this.f1833a = f;
        }

        public c a(c cVar) {
            return cVar instanceof i ? cVar : new b(this.f1833a, cVar);
        }
    }

    static final class c extends Drawable.ConstantState {

        /* renamed from: a  reason: collision with root package name */
        public k f1834a;

        /* renamed from: b  reason: collision with root package name */
        public c.b.a.b.v.a f1835b;

        /* renamed from: c  reason: collision with root package name */
        public ColorFilter f1836c;

        /* renamed from: d  reason: collision with root package name */
        public ColorStateList f1837d = null;
        public ColorStateList e = null;
        public ColorStateList f = null;
        public ColorStateList g = null;
        public PorterDuff.Mode h = PorterDuff.Mode.SRC_IN;
        public Rect i = null;
        public float j = 1.0f;
        public float k = 1.0f;
        public float l;
        public int m = 255;
        public float n = 0.0f;
        public float o = 0.0f;
        public float p = 0.0f;
        public int q = 0;
        public int r = 0;
        public int s = 0;
        public int t = 0;
        public boolean u = false;
        public Paint.Style v = Paint.Style.FILL_AND_STROKE;

        public c(c cVar) {
            this.f1834a = cVar.f1834a;
            this.f1835b = cVar.f1835b;
            this.l = cVar.l;
            this.f1836c = cVar.f1836c;
            this.f1837d = cVar.f1837d;
            this.e = cVar.e;
            this.h = cVar.h;
            this.g = cVar.g;
            this.m = cVar.m;
            this.j = cVar.j;
            this.s = cVar.s;
            this.q = cVar.q;
            this.u = cVar.u;
            this.k = cVar.k;
            this.n = cVar.n;
            this.o = cVar.o;
            this.p = cVar.p;
            this.r = cVar.r;
            this.t = cVar.t;
            this.f = cVar.f;
            this.v = cVar.v;
            if (cVar.i != null) {
                this.i = new Rect(cVar.i);
            }
        }

        public c(k kVar, c.b.a.b.v.a aVar) {
            this.f1834a = kVar;
            this.f1835b = aVar;
        }

        public int getChangingConfigurations() {
            return 0;
        }

        public Drawable newDrawable() {
            g gVar = new g(this, (a) null);
            boolean unused = gVar.e = true;
            return gVar;
        }
    }

    public g() {
        this(new k());
    }

    public g(Context context, AttributeSet attributeSet, int i2, int i3) {
        this(k.e(context, attributeSet, i2, i3).m());
    }

    private g(c cVar) {
        this.f1830c = new m.g[4];
        this.f1831d = new m.g[4];
        this.f = new Matrix();
        this.g = new Path();
        this.h = new Path();
        this.i = new RectF();
        this.j = new RectF();
        this.k = new Region();
        this.l = new Region();
        this.n = new Paint(1);
        this.o = new Paint(1);
        this.p = new c.b.a.b.b0.a();
        this.r = new l();
        this.v = new RectF();
        this.f1829b = cVar;
        this.o.setStyle(Paint.Style.STROKE);
        this.n.setStyle(Paint.Style.FILL);
        w.setColor(-1);
        w.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
        e0();
        d0(getState());
        this.q = new a();
    }

    /* synthetic */ g(c cVar, a aVar) {
        this(cVar);
    }

    public g(k kVar) {
        this(new c(kVar, (c.b.a.b.v.a) null));
    }

    private float C() {
        if (K()) {
            return this.o.getStrokeWidth() / 2.0f;
        }
        return 0.0f;
    }

    private boolean I() {
        c cVar = this.f1829b;
        int i2 = cVar.q;
        return i2 != 1 && cVar.r > 0 && (i2 == 2 || R());
    }

    private boolean J() {
        Paint.Style style = this.f1829b.v;
        return style == Paint.Style.FILL_AND_STROKE || style == Paint.Style.FILL;
    }

    private boolean K() {
        Paint.Style style = this.f1829b.v;
        return (style == Paint.Style.FILL_AND_STROKE || style == Paint.Style.STROKE) && this.o.getStrokeWidth() > 0.0f;
    }

    private void M() {
        super.invalidateSelf();
    }

    private static int P(int i2, int i3) {
        return (i2 * (i3 + (i3 >>> 7))) >>> 8;
    }

    private void Q(Canvas canvas) {
        int y = y();
        int z = z();
        if (Build.VERSION.SDK_INT < 21) {
            Rect clipBounds = canvas.getClipBounds();
            int i2 = this.f1829b.r;
            clipBounds.inset(-i2, -i2);
            clipBounds.offset(y, z);
            canvas.clipRect(clipBounds, Region.Op.REPLACE);
        }
        canvas.translate((float) y, (float) z);
    }

    private boolean R() {
        return Build.VERSION.SDK_INT < 21 || (!O() && !this.g.isConvex());
    }

    private boolean d0(int[] iArr) {
        boolean z;
        int color;
        int colorForState;
        int color2;
        int colorForState2;
        if (this.f1829b.f1837d == null || (color2 = this.n.getColor()) == (colorForState2 = this.f1829b.f1837d.getColorForState(iArr, color2))) {
            z = false;
        } else {
            this.n.setColor(colorForState2);
            z = true;
        }
        if (this.f1829b.e == null || (color = this.o.getColor()) == (colorForState = this.f1829b.e.getColorForState(iArr, color))) {
            return z;
        }
        this.o.setColor(colorForState);
        return true;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:1:0x0002, code lost:
        r2 = r2.getColor();
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private android.graphics.PorterDuffColorFilter e(android.graphics.Paint r2, boolean r3) {
        /*
            r1 = this;
            if (r3 == 0) goto L_0x0014
            int r2 = r2.getColor()
            int r3 = r1.k(r2)
            if (r3 == r2) goto L_0x0014
            android.graphics.PorterDuffColorFilter r2 = new android.graphics.PorterDuffColorFilter
            android.graphics.PorterDuff$Mode r0 = android.graphics.PorterDuff.Mode.SRC_IN
            r2.<init>(r3, r0)
            return r2
        L_0x0014:
            r2 = 0
            return r2
        */
        throw new UnsupportedOperationException("Method not decompiled: c.b.a.b.c0.g.e(android.graphics.Paint, boolean):android.graphics.PorterDuffColorFilter");
    }

    private boolean e0() {
        PorterDuffColorFilter porterDuffColorFilter = this.s;
        PorterDuffColorFilter porterDuffColorFilter2 = this.t;
        c cVar = this.f1829b;
        this.s = j(cVar.g, cVar.h, this.n, true);
        c cVar2 = this.f1829b;
        this.t = j(cVar2.f, cVar2.h, this.o, false);
        c cVar3 = this.f1829b;
        if (cVar3.u) {
            this.p.d(cVar3.g.getColorForState(getState(), 0));
        }
        return !b.f.k.c.a(porterDuffColorFilter, this.s) || !b.f.k.c.a(porterDuffColorFilter2, this.t);
    }

    private void f(RectF rectF, Path path) {
        g(rectF, path);
        if (this.f1829b.j != 1.0f) {
            this.f.reset();
            Matrix matrix = this.f;
            float f2 = this.f1829b.j;
            matrix.setScale(f2, f2, rectF.width() / 2.0f, rectF.height() / 2.0f);
            path.transform(this.f);
        }
        path.computeBounds(this.v, true);
    }

    private void f0() {
        float H = H();
        this.f1829b.r = (int) Math.ceil((double) (0.75f * H));
        this.f1829b.s = (int) Math.ceil((double) (H * 0.25f));
        e0();
        M();
    }

    private void h() {
        k x = B().x(new b(this, -C()));
        this.m = x;
        this.r.d(x, this.f1829b.k, u(), this.h);
    }

    private PorterDuffColorFilter i(ColorStateList colorStateList, PorterDuff.Mode mode, boolean z) {
        int colorForState = colorStateList.getColorForState(getState(), 0);
        if (z) {
            colorForState = k(colorForState);
        }
        return new PorterDuffColorFilter(colorForState, mode);
    }

    private PorterDuffColorFilter j(ColorStateList colorStateList, PorterDuff.Mode mode, Paint paint, boolean z) {
        return (colorStateList == null || mode == null) ? e(paint, z) : i(colorStateList, mode, z);
    }

    private int k(int i2) {
        float H = H() + x();
        c.b.a.b.v.a aVar = this.f1829b.f1835b;
        return aVar != null ? aVar.c(i2, H) : i2;
    }

    public static g l(Context context, float f2) {
        int b2 = c.b.a.b.s.a.b(context, c.b.a.b.b.colorSurface, g.class.getSimpleName());
        g gVar = new g();
        gVar.L(context);
        gVar.U(ColorStateList.valueOf(b2));
        gVar.T(f2);
        return gVar;
    }

    private void m(Canvas canvas) {
        if (this.f1829b.s != 0) {
            canvas.drawPath(this.g, this.p.c());
        }
        for (int i2 = 0; i2 < 4; i2++) {
            this.f1830c[i2].b(this.p, this.f1829b.r, canvas);
            this.f1831d[i2].b(this.p, this.f1829b.r, canvas);
        }
        int y = y();
        int z = z();
        canvas.translate((float) (-y), (float) (-z));
        canvas.drawPath(this.g, w);
        canvas.translate((float) y, (float) z);
    }

    private void n(Canvas canvas) {
        p(canvas, this.n, this.g, this.f1829b.f1834a, t());
    }

    private void p(Canvas canvas, Paint paint, Path path, k kVar, RectF rectF) {
        if (kVar.u(rectF)) {
            float a2 = kVar.t().a(rectF);
            canvas.drawRoundRect(rectF, a2, a2, paint);
            return;
        }
        canvas.drawPath(path, paint);
    }

    private void q(Canvas canvas) {
        p(canvas, this.o, this.h, this.m, u());
    }

    private RectF u() {
        RectF t2 = t();
        float C = C();
        this.j.set(t2.left + C, t2.top + C, t2.right - C, t2.bottom - C);
        return this.j;
    }

    public int A() {
        return this.f1829b.r;
    }

    public k B() {
        return this.f1829b.f1834a;
    }

    public ColorStateList D() {
        return this.f1829b.g;
    }

    public float E() {
        return this.f1829b.f1834a.r().a(t());
    }

    public float F() {
        return this.f1829b.f1834a.t().a(t());
    }

    public float G() {
        return this.f1829b.p;
    }

    public float H() {
        return v() + G();
    }

    public void L(Context context) {
        this.f1829b.f1835b = new c.b.a.b.v.a(context);
        f0();
    }

    public boolean N() {
        c.b.a.b.v.a aVar = this.f1829b.f1835b;
        return aVar != null && aVar.d();
    }

    public boolean O() {
        return this.f1829b.f1834a.u(t());
    }

    public void S(float f2) {
        setShapeAppearanceModel(this.f1829b.f1834a.w(f2));
    }

    public void T(float f2) {
        c cVar = this.f1829b;
        if (cVar.o != f2) {
            cVar.o = f2;
            f0();
        }
    }

    public void U(ColorStateList colorStateList) {
        c cVar = this.f1829b;
        if (cVar.f1837d != colorStateList) {
            cVar.f1837d = colorStateList;
            onStateChange(getState());
        }
    }

    public void V(float f2) {
        c cVar = this.f1829b;
        if (cVar.k != f2) {
            cVar.k = f2;
            this.e = true;
            invalidateSelf();
        }
    }

    public void W(int i2, int i3, int i4, int i5) {
        c cVar = this.f1829b;
        if (cVar.i == null) {
            cVar.i = new Rect();
        }
        this.f1829b.i.set(i2, i3, i4, i5);
        this.u = this.f1829b.i;
        invalidateSelf();
    }

    public void X(float f2) {
        c cVar = this.f1829b;
        if (cVar.n != f2) {
            cVar.n = f2;
            f0();
        }
    }

    public void Y(int i2) {
        c cVar = this.f1829b;
        if (cVar.t != i2) {
            cVar.t = i2;
            M();
        }
    }

    public void Z(float f2, int i2) {
        c0(f2);
        b0(ColorStateList.valueOf(i2));
    }

    public void a0(float f2, ColorStateList colorStateList) {
        c0(f2);
        b0(colorStateList);
    }

    public void b0(ColorStateList colorStateList) {
        c cVar = this.f1829b;
        if (cVar.e != colorStateList) {
            cVar.e = colorStateList;
            onStateChange(getState());
        }
    }

    public void c0(float f2) {
        this.f1829b.l = f2;
        invalidateSelf();
    }

    public void draw(Canvas canvas) {
        this.n.setColorFilter(this.s);
        int alpha = this.n.getAlpha();
        this.n.setAlpha(P(alpha, this.f1829b.m));
        this.o.setColorFilter(this.t);
        this.o.setStrokeWidth(this.f1829b.l);
        int alpha2 = this.o.getAlpha();
        this.o.setAlpha(P(alpha2, this.f1829b.m));
        if (this.e) {
            h();
            f(t(), this.g);
            this.e = false;
        }
        if (I()) {
            canvas.save();
            Q(canvas);
            int width = (int) (this.v.width() - ((float) getBounds().width()));
            int height = (int) (this.v.height() - ((float) getBounds().height()));
            Bitmap createBitmap = Bitmap.createBitmap(((int) this.v.width()) + (this.f1829b.r * 2) + width, ((int) this.v.height()) + (this.f1829b.r * 2) + height, Bitmap.Config.ARGB_8888);
            Canvas canvas2 = new Canvas(createBitmap);
            float f2 = (float) ((getBounds().left - this.f1829b.r) - width);
            float f3 = (float) ((getBounds().top - this.f1829b.r) - height);
            canvas2.translate(-f2, -f3);
            m(canvas2);
            canvas.drawBitmap(createBitmap, f2, f3, (Paint) null);
            createBitmap.recycle();
            canvas.restore();
        }
        if (J()) {
            n(canvas);
        }
        if (K()) {
            q(canvas);
        }
        this.n.setAlpha(alpha);
        this.o.setAlpha(alpha2);
    }

    /* access modifiers changed from: protected */
    public final void g(RectF rectF, Path path) {
        l lVar = this.r;
        c cVar = this.f1829b;
        k kVar = cVar.f1834a;
        float f2 = cVar.k;
        lVar.e(kVar, f2, rectF, this.q, path);
    }

    public Drawable.ConstantState getConstantState() {
        return this.f1829b;
    }

    public int getOpacity() {
        return -3;
    }

    @TargetApi(21)
    public void getOutline(Outline outline) {
        if (this.f1829b.q != 2) {
            if (O()) {
                outline.setRoundRect(getBounds(), E());
                return;
            }
            f(t(), this.g);
            if (this.g.isConvex()) {
                outline.setConvexPath(this.g);
            }
        }
    }

    public boolean getPadding(Rect rect) {
        Rect rect2 = this.u;
        if (rect2 == null) {
            return super.getPadding(rect);
        }
        rect.set(rect2);
        return true;
    }

    public Region getTransparentRegion() {
        this.k.set(getBounds());
        f(t(), this.g);
        this.l.setPath(this.g, this.k);
        this.k.op(this.l, Region.Op.DIFFERENCE);
        return this.k;
    }

    public void invalidateSelf() {
        this.e = true;
        super.invalidateSelf();
    }

    /* JADX WARNING: Code restructure failed: missing block: B:10:0x001e, code lost:
        r0 = r1.f1829b.e;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:14:0x002a, code lost:
        r0 = r1.f1829b.f1837d;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:2:0x0006, code lost:
        r0 = r1.f1829b.g;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:6:0x0012, code lost:
        r0 = r1.f1829b.f;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public boolean isStateful() {
        /*
            r1 = this;
            boolean r0 = super.isStateful()
            if (r0 != 0) goto L_0x0039
            c.b.a.b.c0.g$c r0 = r1.f1829b
            android.content.res.ColorStateList r0 = r0.g
            if (r0 == 0) goto L_0x0012
            boolean r0 = r0.isStateful()
            if (r0 != 0) goto L_0x0039
        L_0x0012:
            c.b.a.b.c0.g$c r0 = r1.f1829b
            android.content.res.ColorStateList r0 = r0.f
            if (r0 == 0) goto L_0x001e
            boolean r0 = r0.isStateful()
            if (r0 != 0) goto L_0x0039
        L_0x001e:
            c.b.a.b.c0.g$c r0 = r1.f1829b
            android.content.res.ColorStateList r0 = r0.e
            if (r0 == 0) goto L_0x002a
            boolean r0 = r0.isStateful()
            if (r0 != 0) goto L_0x0039
        L_0x002a:
            c.b.a.b.c0.g$c r0 = r1.f1829b
            android.content.res.ColorStateList r0 = r0.f1837d
            if (r0 == 0) goto L_0x0037
            boolean r0 = r0.isStateful()
            if (r0 == 0) goto L_0x0037
            goto L_0x0039
        L_0x0037:
            r0 = 0
            goto L_0x003a
        L_0x0039:
            r0 = 1
        L_0x003a:
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: c.b.a.b.c0.g.isStateful():boolean");
    }

    public Drawable mutate() {
        this.f1829b = new c(this.f1829b);
        return this;
    }

    /* access modifiers changed from: protected */
    public void o(Canvas canvas, Paint paint, Path path, RectF rectF) {
        p(canvas, paint, path, this.f1829b.f1834a, rectF);
    }

    /* access modifiers changed from: protected */
    public void onBoundsChange(Rect rect) {
        this.e = true;
        super.onBoundsChange(rect);
    }

    /* access modifiers changed from: protected */
    public boolean onStateChange(int[] iArr) {
        boolean z = d0(iArr) || e0();
        if (z) {
            invalidateSelf();
        }
        return z;
    }

    public float r() {
        return this.f1829b.f1834a.j().a(t());
    }

    public float s() {
        return this.f1829b.f1834a.l().a(t());
    }

    public void setAlpha(int i2) {
        c cVar = this.f1829b;
        if (cVar.m != i2) {
            cVar.m = i2;
            M();
        }
    }

    public void setColorFilter(ColorFilter colorFilter) {
        this.f1829b.f1836c = colorFilter;
        M();
    }

    public void setShapeAppearanceModel(k kVar) {
        this.f1829b.f1834a = kVar;
        invalidateSelf();
    }

    public void setTint(int i2) {
        setTintList(ColorStateList.valueOf(i2));
    }

    public void setTintList(ColorStateList colorStateList) {
        this.f1829b.g = colorStateList;
        e0();
        M();
    }

    public void setTintMode(PorterDuff.Mode mode) {
        c cVar = this.f1829b;
        if (cVar.h != mode) {
            cVar.h = mode;
            e0();
            M();
        }
    }

    /* access modifiers changed from: protected */
    public RectF t() {
        Rect bounds = getBounds();
        this.i.set((float) bounds.left, (float) bounds.top, (float) bounds.right, (float) bounds.bottom);
        return this.i;
    }

    public float v() {
        return this.f1829b.o;
    }

    public ColorStateList w() {
        return this.f1829b.f1837d;
    }

    public float x() {
        return this.f1829b.n;
    }

    public int y() {
        c cVar = this.f1829b;
        return (int) (((double) cVar.s) * Math.sin(Math.toRadians((double) cVar.t)));
    }

    public int z() {
        c cVar = this.f1829b;
        return (int) (((double) cVar.s) * Math.cos(Math.toRadians((double) cVar.t)));
    }
}
